package com.kfm.jdbc.day01;

import java.sql.*;

public class Demo06 {

    static {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] args) {
        String url = "jdbc:mysql://localhost:3306/company_info";
        String user = "root";
        String pass = "root";

        String sql = "insert into login (username, password) values(?, ?)";
        try(Connection conn = DriverManager.getConnection(url, user, pass);
            PreparedStatement preparedStatement = conn.prepareStatement(sql)
        ) {
            for (int i = 0; i < 10; i++) {
                preparedStatement.setString(1, "ps" + i);
                preparedStatement.setString(2, "222222");

                preparedStatement.executeUpdate();
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }


    }

    public static void batchInsert(){
        String url = "jdbc:mysql://localhost:3306/company_info";
        String user = "root";
        String pass = "root";
        try (Connection connection = DriverManager.getConnection(url, user, pass);
             Statement statement = connection.createStatement();){
            for (int i = 0; i < 10; i++) {
                String u = "test";
                String p = "111111";
                String sql = "insert into login (username, password) values('%s', '%s')".formatted(u + i, p);

                statement.executeUpdate(sql);
            }

        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }



}
